﻿using System.ComponentModel.Composition;
using System.Windows;
using MediaAssistant.Constants;
using MediaAssistant.Controls.MovieList;
using MediaAssistant.Controls.MovieThumbnails;
using MediaAssistant.Controls.WaitScreen;
using MediaAssistant.Data;
using MefBasic;
using Microsoft.Practices.Composite.Regions;

namespace MediaAssistant.Controls.MovieMiddleToolBar
{
    [Export]
    public class MovieMiddleToolBarPresenter:APresenter<MovieMiddleToolBarView>
    {
        [ImportingConstructor]
        public MovieMiddleToolBarPresenter(MovieMiddleToolBarView view) : base(view)
        {
            
        }
        [Import]
        private IRegionManager RegionManager { get; set; }

        [Import]
        private MovieListPresenter MovieListPresenter { get; set; }

        [Import]
        private MovieThumbnailsPresenter MovieThumbnailsPresenter { get; set; }

        [Import]
        private WaitScreenPresenter WaitScreen { get; set; }
        [Import]
        public LibraryDataSource DataSource
        {
            get { return (LibraryDataSource)GetValue(DataSourceProperty); }
            set { SetValue(DataSourceProperty, value); }
        }

        public static readonly DependencyProperty DataSourceProperty =
            DependencyProperty.Register("DataSource", typeof(LibraryDataSource), typeof(MovieMiddleToolBarPresenter), new UIPropertyMetadata(null));

        public bool IsListView
        {
            get { return (bool)GetValue(IsListViewProperty); }
            set { SetValue(IsListViewProperty, value); }
        }

        public static readonly DependencyProperty IsListViewProperty =
            DependencyProperty.Register("IsListView", typeof(bool), typeof(MovieMiddleToolBarPresenter), new UIPropertyMetadata(true, OnPropertyChanged));

        protected override void DoPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            switch (e.Property.Name)
            {
                case "IsListView":
                    WaitScreen.Show();
                    if(IsListView)
                    {
                        RegionManager.Regions[MediaAssistantRegionNames.MovieResultResion].Activate(MovieListPresenter.View);
                    }
                    else
                    {
                        RegionManager.Regions[MediaAssistantRegionNames.MovieResultResion].Activate(MovieThumbnailsPresenter.View);
                    }
                    WaitScreen.Hide();
                    break;
            }
        }
    }
}
